/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 22652
 * Date: 2024-09-09
 * Time: 11:04
 */
public class moving_Zero {
    public static void moveZeroes(int[] nums) {
        int cur=0;
        int dest=-1;
        //数组分块
        //0--dest不为零的区域，dest+1--cur为零，cur--n-1未处理区域
        int n=nums.length;
        for (; cur < n; cur++) {
            if (nums[cur]!=0){
                dest++;
                int tmp=nums[cur];
                nums[cur]=nums[dest];
                nums[dest]=tmp;
            }
        }
    }

    public static void main(String[] args) {
        int[] arr=new int[]{0,1,0,3,12};
        moveZeroes(arr);
    }
}
